#ifndef __EV_SATELLITE_ORB_DATA_H__
#define __EV_SATELLITE_ORB_DATA_H__


#include<stdint.h>
#include<string>
#include<vector>
#include"rapidjson/document.h"


namespace SC_SUN
{

struct EvSatelliteORBData
{

//////基本信息//////
/*
长度：5位
范围：1- SAT_NUM
格式：SAT+XXXXX
【SAT0000*】
【SAT000**】
【SAT00***】
【SAT0****】
【SAT*****】
*/
std::string SAT_SN;                                     ///< 卫星创建序号
std::vector<double> SAT_ST_HF;                          ///< 高精度仿真时序列，单位：秒

//////高精度轨道信息//////
std::vector<double> SAT_POS_HF;							///< 高精度位置矢量序列，单位：千米
std::vector<double> SAT_VEL_HF;							///< 高精度速度矢量序列，单位：千米/秒

//////预测轨道信息//////
std::vector<double> SAT_POS_MS;							///< 预测位置矢量序列，单位：千米
std::vector<double> SAT_VEL_MS;							///< 预测速度矢量序列，单位：千米/秒

//////轨道误差信息//////
std::vector<double> SAT_POS_ER;							///< 位置误差序列，单位：千米
std::vector<double> SAT_VEL_ER;							///< 速度误差序列，单位：千米/秒

//////环境信息//////
std::vector<double> SUN_POS;							///< 太阳位置序列，单位：千米
std::vector<double> LNR_POS;							///< 月球位置序列，单位：千米
std::vector<double> EAR_NUT;                            ///< 地球章动角序列，单位：度
std::vector<double> EAR_PRE;                            ///< 地球进动角序列，单位：度
std::vector<double> EAR_ROT;                            ///< 地球自转角序列，单位：度
std::vector<double> HDF_ER;								///< 热变形安装位置误差序列，坐标系：本体系，单位：米
std::vector<double> PrtDvaMat;                          ///< 状态转移矩阵，double【6*6】

auto ObjToJsonObject(rapidjson::Document& doc)
{
    using namespace rapidjson;

    Value obj(kObjectType);

    obj.AddMember(Value("SAT_SN", doc.GetAllocator()), Value(SAT_SN.data(), doc.GetAllocator()), doc.GetAllocator());

    Value value1(kArrayType);
    for (int i = 0; i < SAT_ST_HF.size(); i++)
    {
        value1.PushBack(SAT_ST_HF[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SAT_ST_HF", doc.GetAllocator()), value1, doc.GetAllocator());

    Value value2(kArrayType);
    for (int i = 0; i < SAT_POS_HF.size(); i++)
    {
        value2.PushBack(SAT_POS_HF[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SAT_POS_HF", doc.GetAllocator()), value2, doc.GetAllocator());

    Value value3(kArrayType);
    for (int i = 0; i < SAT_VEL_HF.size(); i++)
    {
        value3.PushBack(SAT_VEL_HF[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SAT_VEL_HF", doc.GetAllocator()), value3, doc.GetAllocator());

    Value value4(kArrayType);
    for (int i = 0; i < SAT_POS_MS.size(); i++)
    {
        value4.PushBack(SAT_POS_MS[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SAT_POS_MS", doc.GetAllocator()), value4, doc.GetAllocator());

    Value value5(kArrayType);
    for (int i = 0; i < SAT_VEL_MS.size(); i++)
    {
        value5.PushBack(SAT_VEL_MS[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SAT_VEL_MS", doc.GetAllocator()), value5, doc.GetAllocator());

    Value value6(kArrayType);
    for (int i = 0; i < SAT_POS_ER.size(); i++)
    {
        value6.PushBack(SAT_POS_ER[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SAT_POS_ER", doc.GetAllocator()), value6, doc.GetAllocator());

    Value value7(kArrayType);
    for (int i = 0; i < SAT_VEL_ER.size(); i++)
    {
        value7.PushBack(SAT_VEL_ER[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SAT_VEL_ER", doc.GetAllocator()), value7, doc.GetAllocator());

    Value value8(kArrayType);
    for (int i = 0; i < SUN_POS.size(); i++)
    {
        value8.PushBack(SUN_POS[i], doc.GetAllocator());
    }
    obj.AddMember(Value("SUN_POS", doc.GetAllocator()), value8, doc.GetAllocator());

    Value value9(kArrayType);
    for (int i = 0; i < LNR_POS.size(); i++)
    {
        value9.PushBack(LNR_POS[i], doc.GetAllocator());
    }
    obj.AddMember(Value("LNR_POS", doc.GetAllocator()), value9, doc.GetAllocator());

    Value value10(kArrayType);
    for (int i = 0; i < EAR_NUT.size(); i++)
    {
        value10.PushBack(EAR_NUT[i], doc.GetAllocator());
    }
    obj.AddMember(Value("EAR_NUT", doc.GetAllocator()), value10, doc.GetAllocator());

    Value value11(kArrayType);
    for (int i = 0; i < EAR_PRE.size(); i++)
    {
        value11.PushBack(EAR_PRE[i], doc.GetAllocator());
    }
    obj.AddMember(Value("EAR_PRE", doc.GetAllocator()), value11, doc.GetAllocator());

    Value value12(kArrayType);
    for (int i = 0; i < EAR_ROT.size(); i++)
    {
        value12.PushBack(EAR_ROT[i], doc.GetAllocator());
    }
    obj.AddMember(Value("EAR_ROT", doc.GetAllocator()), value12, doc.GetAllocator());

    Value value13(kArrayType);
    for (int i = 0; i < HDF_ER.size(); i++)
    {
        value13.PushBack(HDF_ER[i], doc.GetAllocator());
    }
    obj.AddMember(Value("HDF_ER", doc.GetAllocator()), value13, doc.GetAllocator());

    Value value14(kArrayType);
    for (int i = 0; i < PrtDvaMat.size(); i++)
    {
        value14.PushBack(PrtDvaMat[i], doc.GetAllocator());
    }
    obj.AddMember(Value("HDFPrtDvaMat_ER", doc.GetAllocator()), value14, doc.GetAllocator());

    return obj;
}


static EvSatelliteORBData JsonObjectToObject(rapidjson::GenericObject<true, rapidjson::Value> obj)
{
    using namespace rapidjson;

    EvSatelliteORBData ret;

    //auto obj = doc.GetObj();

    ret.SAT_SN = obj["SAT_SN"].GetString();

    auto array1 = obj["SAT_ST_HF"].GetArray();
    for (int i = 0; i < array1.Size(); i++)
    {
       ret.SAT_ST_HF.push_back(array1[i].GetDouble());
    }

    auto array2 = obj["SAT_POS_HF"].GetArray();
    for (int i = 0; i < array2.Size(); i++)
    {
       ret.SAT_POS_HF.push_back(array2[i].GetDouble());
    }

    auto array3 = obj["SAT_VEL_HF"].GetArray();
    for (int i = 0; i < array3.Size(); i++)
    {
       ret.SAT_VEL_HF.push_back(array3[i].GetDouble());
    }

    auto array4 = obj["SAT_POS_MS"].GetArray();
    for (int i = 0; i < array4.Size(); i++)
    {
       ret.SAT_POS_MS.push_back(array4[i].GetDouble());
    }

    auto array5 = obj["SAT_VEL_MS"].GetArray();
    for (int i = 0; i < array5.Size(); i++)
    {
       ret.SAT_VEL_MS.push_back(array5[i].GetDouble());
    }

    auto array6 = obj["SAT_POS_ER"].GetArray();
    for (int i = 0; i < array6.Size(); i++)
    {
       ret.SAT_POS_ER.push_back(array6[i].GetDouble());
    }

    auto array7 = obj["SAT_VEL_ER"].GetArray();
    for (int i = 0; i < array7.Size(); i++)
    {
       ret.SAT_VEL_ER.push_back(array7[i].GetDouble());
    }

    auto array8 = obj["SUN_POS"].GetArray();
    for (int i = 0; i < array8.Size(); i++)
    {
       ret.SUN_POS.push_back(array8[i].GetDouble());
    }

    auto array9 = obj["LNR_POS"].GetArray();
    for (int i = 0; i < array9.Size(); i++)
    {
       ret.LNR_POS.push_back(array9[i].GetDouble());
    }

    auto array10 = obj["EAR_NUT"].GetArray();
    for (int i = 0; i < array10.Size(); i++)
    {
       ret.EAR_NUT.push_back(array10[i].GetDouble());
    }

    auto array11 = obj["EAR_PRE"].GetArray();
    for (int i = 0; i < array11.Size(); i++)
    {
       ret.EAR_PRE.push_back(array11[i].GetDouble());
    }

    auto array12 = obj["EAR_ROT"].GetArray();
    for (int i = 0; i < array12.Size(); i++)
    {
       ret.EAR_ROT.push_back(array12[i].GetDouble());
    }

    auto array13 = obj["HDF_ER"].GetArray();
    for (int i = 0; i < array13.Size(); i++)
    {
       ret.HDF_ER.push_back(array13[i].GetDouble());
    }

    auto array14 = obj["PrtDvaMat"].GetArray();
    for (int i = 0; i < array14.Size(); i++)
    {
       ret.PrtDvaMat.push_back(array14[i].GetDouble());
    }

    return ret;
}


static EvSatelliteORBData JsonObjectToObject2(rapidjson::GenericObject<false, rapidjson::Value> obj)
{
    using namespace rapidjson;

    EvSatelliteORBData ret;

    //auto obj = doc.GetObj();

    ret.SAT_SN = obj["SAT_SN"].GetString();

    auto array1 = obj["SAT_ST_HF"].GetArray();
    for (int i = 0; i < array1.Size(); i++)
    {
        ret.SAT_ST_HF.push_back(array1[i].GetDouble());
    }

    auto array2 = obj["SAT_POS_HF"].GetArray();
    for (int i = 0; i < array2.Size(); i++)
    {
        ret.SAT_POS_HF.push_back(array2[i].GetDouble());
    }

    auto array3 = obj["SAT_VEL_HF"].GetArray();
    for (int i = 0; i < array3.Size(); i++)
    {
        ret.SAT_VEL_HF.push_back(array3[i].GetDouble());
    }

    auto array4 = obj["SAT_POS_MS"].GetArray();
    for (int i = 0; i < array4.Size(); i++)
    {
        ret.SAT_POS_MS.push_back(array4[i].GetDouble());
    }

    auto array5 = obj["SAT_VEL_MS"].GetArray();
    for (int i = 0; i < array5.Size(); i++)
    {
        ret.SAT_VEL_MS.push_back(array5[i].GetDouble());
    }

    auto array6 = obj["SAT_POS_ER"].GetArray();
    for (int i = 0; i < array6.Size(); i++)
    {
        ret.SAT_POS_ER.push_back(array6[i].GetDouble());
    }

    auto array7 = obj["SAT_VEL_ER"].GetArray();
    for (int i = 0; i < array7.Size(); i++)
    {
        ret.SAT_VEL_ER.push_back(array7[i].GetDouble());
    }

    auto array8 = obj["SUN_POS"].GetArray();
    for (int i = 0; i < array8.Size(); i++)
    {
        ret.SUN_POS.push_back(array8[i].GetDouble());
    }

    auto array9 = obj["LNR_POS"].GetArray();
    for (int i = 0; i < array9.Size(); i++)
    {
        ret.LNR_POS.push_back(array9[i].GetDouble());
    }

    auto array10 = obj["EAR_NUT"].GetArray();
    for (int i = 0; i < array10.Size(); i++)
    {
        ret.EAR_NUT.push_back(array10[i].GetDouble());
    }

    auto array11 = obj["EAR_PRE"].GetArray();
    for (int i = 0; i < array11.Size(); i++)
    {
        ret.EAR_PRE.push_back(array11[i].GetDouble());
    }

    auto array12 = obj["EAR_ROT"].GetArray();
    for (int i = 0; i < array12.Size(); i++)
    {
        ret.EAR_ROT.push_back(array12[i].GetDouble());
    }

    auto array13 = obj["HDF_ER"].GetArray();
    for (int i = 0; i < array13.Size(); i++)
    {
        ret.HDF_ER.push_back(array13[i].GetDouble());
    }

    auto array14 = obj["PrtDvaMat"].GetArray();
    for (int i = 0; i < array14.Size(); i++)
    {
        ret.PrtDvaMat.push_back(array14[i].GetDouble());
    }

    return ret;
}

};

}

#endif